package com.jake.data_structure_learning.solution;

/**
 * copyright (C), 2021, 武汉德辞信息技术有限公司
 *
 * @author WangXiang
 * @version 1.0.0
 * @create 2021/7/15 13:38
 * @description <author>                <time>                  <version>
 * WangXiang               2021/7/15 13:38            1.0.0
 */
public class Solution2 {

    public int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return 1;
        }

        int left = 0;
        for (int right = 1; right < nums.length; right++) {
            if (nums[left] != nums[right]) {
                left++;
                nums[left] = nums[right];
            }
        }
        return ++left;
    }

    public int maxProfit(int[] prices) {
        int mp = 0;
        if (prices == null || prices.length < 1) {
            return mp;
        }
        for (int i = 1; i < prices.length; i++) {
            mp += Math.max(0, prices[i] - prices[i - 1]);
        }
        return mp;
    }
}
